<template>
  <div class="chart-pie" ref="chart"></div>
</template>

<script>
export default {
  name: "EchartPie",
  data() {
    return {};
  },
  props: {
    pieData: {
      type: Object,
      default() {
        return {}
      },
      request: true
    }
  },
  mounted() {
    this.myChart(this.pieData)
  },
  methods: {
    myChart(pieData) {
      var chartDom = this.$refs.chart;
      var myChart = this.$echarts.init(chartDom);
      var option;

      option = {
        backgroundColor: "#fff",
        title: {
          text: "题库数量占比",
          left: "center",
          top: 20,
          textStyle: {
            color: "#041527",
          },
        },

        tooltip: {
          trigger: "item",
        },

        visualMap: {
          show: false,
          min: 80,
          max: 600,
          inRange: {
            colorLightness: [0, 1],
          },
        },

        toolbox: {
          show: true,
          feature: {
            //各工具配置项
            saveAsImage: {},
            // dataView: {
            //   //数据视图
            //   readOnly: false,
            // },
            restore: {},
          },
        },
        series: [
          {
            name: "题库占比",
            type: "pie",
            radius: "55%",
            center: ["50%", "50%"],
            data: [
              { value: pieData.system, name: "动态题库" },
              { value: pieData.common, name: "静态题库" },
            ].sort(function (a, b) {
              return a.value - b.value;
            }),
            roseType: "radius",
            label: {
              color: "rgba(255, 255, 255, 0.3)",
            },
            labelLine: {
              lineStyle: {
                color: "rgba(255, 255, 255, 0.3)",
              },
              smooth: 0.2,
              length: 10,
              length2: 20,
            },
            itemStyle: {
              color: "#c23531",
              shadowBlur: 200,
              shadowColor: "rgba(0, 0, 0, 0.1)",
            },

            animationType: "scale",
            animationEasing: "elasticOut",
            animationDelay: function (idx) {
              return Math.random() * 200;
            },
          },
        ],
      };
      option && myChart.setOption(option);
    },
  },
};
</script>

<style scoped>
.chart-pie {
  width: calc(100vw - 408px);   
  height: 300px;
}
</style>
